n = 1.2
print(type(n))
# 转为 int
b = int(n)
print(type(b))
print(int(3.14))
b = int('145')
print(b, type(b))
# 转为 float
c = float('135')
print(c, type(c))
# 转为 str
s = str(246)
print(s, type(s))
# eval 执行一个字符串表达式
print(eval('10+10'))
st1 = "[[1,2],[3,4],[5,6]]"
print(type(st1))

li = eval(st1)
print(li, type(li))

st2 = "{'name':'zhangsan','age':16}"
dic = eval(st2)
print(dic, type(dic))

# list()
# 字符串转为 list
print(list('abcdefg'))
# 元组转为 list
print(list((1, 23, 4, 5, 53)))
# 字典转为 list
print(list({'name': 'zhangsan', 'age': 25}))
# 集合转为 list
print(list({1, 4, 523, 5, 23, 'a', 'b', 'c', 'd'}))

# 深浅拷贝
# 赋值 数据完全共享
li = [1, 2, 3, 4, 5]
li2 = li
print("li", li)
print("li2", li2)
li.append(6)
print("li的内存地址：", id(li))
print("li2的内存地址：", id(li2))
print("新增后li", li)
print("新增后li2", li2)
import copy

li = [1, 2, 3, [4, 5, 6]]
# 浅拷贝 数据部分共享
li2 = copy.copy(li)
print(li2)
print("li的内存地址：", id(li))
print("li2的内存地址：", id(li2))
li.append(7)
print("浅拷贝内层li[3]地址", id(li[3]))
print("浅拷贝内层li2[3]地址", id(li2[3]))
print(id(li2[3]))
# 深拷贝 数据完全不共享
li = [1, 2, 3, [4, 5, 6]]
li2 = copy.deepcopy(li)
print("li:", li, id(li))
print("li2:", li2, id(li2))
li.append(8)
print("li:", li, id(li))
print("li2:", li2, id(li2))
li[3].append(7)
print("li:", li, id(li))
print("li2:", li2, id(li2))
print("深拷贝li[3]地址", id(li[3]))
print("深拷贝li2[3]地址", id(li2[3]))
# 可变类型
li = [1, 2, 3, 4]
print("li的内存地址：", id(li))
li.append(5)
print(li)
dic = {'name': 'zhangsan', 'age': 18}
print(dic, id(dic))
dic['name'] = 'lisi'
print(dic, id(dic))
# 可变对象赋值不回从新分配内存
set = {1, 2, 3, 4, 5}
print(id(set))
set.remove(3)
print(id(set))
# 不可变对象赋值会从新分配内存
n = 10
print(id(n))
n = 15
print(id(n))

tun = (1, 2, 3)
print(id(tun))
tun = (3, 4, 5)
print(id(tun))

